// import { VantResolver } from "@vant/auto-import-resolver";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import postCssPxToRem from "postcss-pxtorem";
// import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import { defineConfig, loadEnv } from "vite";
import vike from "vike/plugin";

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    base: env.VITE_BASE_PATH || "/",
    resolve: {
      alias: { "@": resolve(__dirname, "src") },
    },
    css: {
      postcss: {
        plugins: [
          postCssPxToRem({
            rootValue: 37.5,
            propList: ["*"],
            selectorBlackList: ["-norem"],
          }),
        ],
      },
    },
    ssr: {
      noExternal: ["ant-design-vue", "@ant-design/icons-vue", "vue-i18n"],
    },
    plugins: [
      vue(),
      // AutoImport({}),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      }),
      vike({ prerender: true }),
    ],
    server: {
      proxy: {
        "/pc": {
          target: "https://wxapp.gangmeimaoyi.cn",
          changeOrigin: true,
          secure: false,
          ws: true,
          // rewrite: (path) => path.replace(/^\/api/, ""),
        },
        "/api": {
          target: "https://wxapp.gangmeimaoyi.cn",
          changeOrigin: true,
          secure: false,
          ws: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  };
});
